package com.lj.utils.utils;

import java.util.HashMap;
import java.util.Map;

public class Parser {


    public static String parse(String text, Map<String, String> map) {
        //判断文本是否为空
        if (text == null || text.isEmpty()) {
            return "";
        }
        //判断map是否为空
        if (map == null || map.size()==0) {
            return text;
        }

        for (Map.Entry<String, String> entry : map.entrySet()) {
            String K = entry.getKey();
            String V = entry.getValue();
            text = text.replaceAll("\\{" + K + "}", V);
        }


        return text;
    }

    /**
     * 使用示例
     *
     * @param args
     */
    public static void main(String[] args) {
        String url = "http://localhost:8080/test?name={name}&Age={age}&sex={sex}";
        HashMap<String, String> map = new HashMap<>();
        map.put("name","aaa");
        map.put("age","18");
        String parse = parse(url, map);
        System.out.println(parse);
    }
}
